package io.sage.modules.goods.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import io.sage.modules.goods.dao.BGoodsMapper;
import io.sage.modules.goods.entity.BGoods;
import io.sage.modules.goods.enums.GoodsStatusEnum;
import io.sage.modules.goods.service.BGoodsService;

@Service("goodsService")
public class BGoodsServiceImpl implements BGoodsService {
	
	@Autowired
	private BGoodsMapper goodsMapper;
	
	/**
     * 货物列表
     * @param params
     * @return
     */
	@Override
	public List<BGoods> selectGoodsList(Map<String, Object> params) {
		return goodsMapper.selectGoodsList(params);
	}
	
	/**
     * 批量删除
     * @param ids
     * @return
     */
	@Override
	public int deleteBatchIds(Integer[] ids) {
		return goodsMapper.deleteBatchIds(ids);
	}
	
	/**
	 * 根据主键id查询货物详情
	 * @param id
	 * @return
	 */
	@Override
	public BGoods selectById(Integer id) {
		return goodsMapper.selectById(id);
	}
	
	/**
	 * 根据主键修改货物信息
	 * @param goods
	 * @return
	 */
	@Override
	public int updateByPrimaryKeySelective(BGoods goods) {
		goods.setUpdateTime(new Date());
		return goodsMapper.updateByPrimaryKeySelective(goods);
	}
	
	/**
	 * 添加货物信息
	 * @param goods
	 * @return
	 */
	@Override
	public int insert(BGoods goods) {
		goods.setCreateTime(new Date());
		goods.setUpdateTime(new Date());
		goods.setIsDel(0);
		goods.setIsUsed(1);
		goods.setGoodsStatus(0);
		return goodsMapper.insertSelective(goods);
	}
	
	/**
	 * 申请工具的接口
	 */
	@Override
	public int applyGoods(Integer id, Integer employeeId) {
		BGoods goods=new BGoods();
		goods.setId(id);
		goods.setGoodsStatus(GoodsStatusEnum.APPLY.getCode());
		
		return goodsMapper.updateByPrimaryKeySelective(goods);
	}

}
